
function LoadLocalhostConfig(){
	// %appdata%/kingsoft/wps/jsaddons
	//let tempPath = Application.Env.GetTempPath();
	let jsaddons = Application.Env.GetAppDataPath() + "/kingsoft/wps/jsaddons/";
	let configFile = jsaddons + 'FeiLuAssist.cfg';
	//let tempPath = Application.Env.GetTempPath();
	//console.log("configFile:",configFile,tempPath,Application.FileSystem);
	
	if (Application.FileSystem.Exists(configFile)){
		let str = Application.FileSystem.ReadFile(configFile);
		//let config = JSON.parse(str);
		//console.log("config:",config);
		Application.PluginStorage.setItem('FeiLuConfig',str);
	}else{
		console.error('配置文件FeiLuAssist.cfg不存在!!：',configFile);
	}
}

LoadLocalhostConfig();

function access_token(){
	let configString = Application.PluginStorage.getItem('FeiLuConfig');
	let config = JSON.parse(configString);
	return config.AccessToken;
	//let token = "14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759";
	//return token;
}
function getMainURL(){
	//return "http://192.168.31.48:5800";
	//return "http://192.168.31.208:6002"
	let configString = Application.PluginStorage.getItem('FeiLuConfig');
	let config = JSON.parse(configString);
	return config.MainURL;
}

function getConfig(){
	let configString = Application.PluginStorage.getItem('FeiLuConfig');
	let config = JSON.parse(configString);
	return config;
}

function getMainClientUserLoginOpenID(){
	let conf = getConfig();
	if(conf && conf.MainClientDevice){
		return conf.MainClientDevice.UserLoginOpenID;
	}
	return "";
}

function getMainClientDeviceCode(){
	let conf = getConfig();
	if(conf && conf.MainClientDevice){
		return conf.MainClientDevice.DeviceCode;
	}
	return "";
}

let app = Application;
//console.log(app.Env)

// 展示任务栏
function showTaskPanA(dateSTR,customerName,drumNo,productName,coolingTotalWeight,orgStoneWeight, nowStoneWeight){
	let tsId = wps.PluginStorage.getItem("taskpane_id")
	if (tsId) {
		let tskpane = wps.GetTaskPane(tsId)
		//tskpane.Visible = true
		tskpane.Delete();
	}
	
	//let tskpane = wps.CreateTaskPane(GetUrlPath() + "/ui/taskpane.html")
	//console.log(GetUrlPath() + "/ui/taskpane.html");
	let querySTR = "/kim/taskPanA?userLoginOpenID="+getConfig().UserLoginOpenID+"&deviceSerial="+getConfig().DeviceCode+"&customerName="+customerName+"&drumNo="+encodeURIComponent(drumNo)+"&productName="+productName+"&dateSTR="+dateSTR+"&coolingTotalWeight="+coolingTotalWeight+"&access_token="+access_token();
	let url = getMainURL() + querySTR;
	//console.log("showTaskPanA URL: %s",url);
	let tskpane = wps.CreateTaskPane(url)
	let id = tskpane.ID
	wps.PluginStorage.setItem("taskpane_id", id)
	tskpane.Visible = true
	//tskpane.DockPosition = wps.Enum.msoCTPDockPositionBottom;
	//console.log("tskpan：",tskpane);
	//console.log("position: ",wps.Enum.msoCTPDockPositionFloating)
	
}

// 展示统计数据
function showTaskPanB(dateSTR,drumNOArray){
	let url = getMainURL() + "/kim/taskPanB?dateSTR="+dateSTR+"&drumNoArray="+drumNOArray+"&access_token="+access_token();
	console.log("showTaskPanB URL: %s",url);
	
	let tsId = wps.PluginStorage.getItem("taskpane_id")
	if (tsId) {
		let tskpane = wps.GetTaskPane(tsId)
		//tskpane.Visible = true
		if(tskpane)
		tskpane.Delete();
	}
	let tskpane = wps.CreateTaskPane(url)
	let id = tskpane.ID
	wps.PluginStorage.setItem("taskpane_id", id)
	tskpane.Visible = true
}

function hideTaskPanA(){
	let tsId = wps.PluginStorage.getItem("taskpane_id")
	if (tsId) {
		let tskpane = wps.GetTaskPane(tsId)
		if(tskpane)
		tskpane.Visible = false
	}
}

// 文档保存后触发
function onFileAfterSave(wb, success){
	let doc = wps.EtApplication().ActiveWorkbook;
	let docFileName = "";
	if (!doc){
		return ;
	}

	docFileName = doc.Name;
	let fullName = wb.FullName;
	//console.log("FullName: ",fullName)
	if(docFileName.indexOf('倒模加工表')>0){
		let url = getMainURL() + "/kim/sendFileOnSave";
		let data = {"access_token":access_token(),"deviceSerial":getMainClientDeviceCode(),"loginOpenID":getMainClientUserLoginOpenID()};
		data.singleFilePath = fullName;
		ActionJS.AjaxPostSP(url,data,function(result){
			if(result.errorCode == 1000){
				console.log("文件保存：",result);
			}
		});
	}
}

function onAfterTaskPaneShow(){
	//console.log("onAfterTaskPaneHidden");
	let dataSTRING = wps.PluginStorage.getItem("taskpane_rowdata");
	let targetSTRING = wps.PluginStorage.getItem("taskpane_rowtarget");
	let data  = $.parseJSON( dataSTRING );
	let Target  = $.parseJSON( targetSTRING );
	let url = getMainURL() + "/kim/queryProductWeightFormula";//?customerName="+customerName+"&drumNo="+drumNo+"&productName="+productName+"&dateSTR="+dateSTR+"&access_token=14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759"
	
	let curSheet = wps.EtApplication().ActiveSheet;
	if(curSheet && data && data.drumNo && data.customerName && data.dateSTR){

		// 获取文件名
		let doc = wps.EtApplication().ActiveWorkbook
		let docFileName = "";
		if (!doc){
			return ;
		}

		docFileName = doc.Name;
		if(docFileName.indexOf('倒模加工表')>0 && Target.Column == 21){
			ActionJS.AjaxPostSP(url,data,function(result){
				console.log("结果2：",result);
				if(result.errorCode == 1000){
					curSheet.Cells.Item(Target.Row,Target.Column).Formula = result.productWeightFormula;
				}
				if(result.errorCode == 1000){
					curSheet.Cells.Item(Target.Row,23).Formula = result.recycleWeight;
				}
				if(result.errorCode == 1000){
					curSheet.Cells.Item(Target.Row,24).Formula = result.cutBrokenWeight;
				}
			});
		}
	}
}

function onAfterTaskPaneHidden(){
	console.log("onAfterTaskPaneHidden");
	let dataSTRING = wps.PluginStorage.getItem("taskpane_rowdata");
	let targetSTRING = wps.PluginStorage.getItem("taskpane_rowtarget");
	let data  = $.parseJSON( dataSTRING );
	let Target  = $.parseJSON( targetSTRING );
	let url = getMainURL() + "/kim/queryProductWeightFormula";//?customerName="+customerName+"&drumNo="+drumNo+"&productName="+productName+"&dateSTR="+dateSTR+"&access_token=14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759"
	
	let curSheet = wps.EtApplication().ActiveSheet;
	if(curSheet && data && data.drumNo && data.customerName && data.dateSTR){

		// 获取文件名
		let doc = wps.EtApplication().ActiveWorkbook
		let docFileName = "";
		if (!doc){
			return ;
		}

		docFileName = doc.Name;
		if(docFileName.indexOf('倒模加工表')>0 && Target.Column == 21){
			ActionJS.AjaxPostSP(url,data,function(result){
				console.log("结果：",result);
				if(result.errorCode == 1000 && result.productWeightFormula){
					curSheet.Cells.Item(Target.Row,Target.Column).Formula = result.productWeightFormula;
				}
				if(result.errorCode == 1000 && result.recycleWeight){
					curSheet.Cells.Item(Target.Row,23).Formula = result.recycleWeight;
				}
				if(result.errorCode == 1000 && result.cutBrokenWeight){
					curSheet.Cells.Item(Target.Row,24).Formula = result.cutBrokenWeight;
				}
			});
		}
		
	}
	
}


function onAfterOrgStoneWeightCellClick(Target,data){
	let url = getMainURL() + "/kim/queryProductWeightFormula";
	let curSheet = wps.EtApplication().ActiveSheet;
	if(curSheet){

		// 获取文件名
		let doc = wps.EtApplication().ActiveWorkbook
		let docFileName = "";
		if (!doc){
			return ;
		}

		docFileName = doc.Name;
		if(docFileName.indexOf('倒模加工表')>0 && Target.Column == 5){
			ActionJS.AjaxPostSP(url,data,function(result){
				// console.log(result);
				if(result.errorCode == 1000 && result.orgStoneWeightFormula){
					let stoneWeight_exp = "";
					if(result.orgStoneWeightFormula.indexOf("=") == 0){
						stoneWeight_exp = result.orgStoneWeightFormula.substring(1);
					}

					try{
						if(eval(""+stoneWeight_exp) != 0){
							curSheet.Cells.Item(Target.Row,Target.Column).Formula = result.orgStoneWeightFormula;
						}
					}catch(err){
						return ;
					}
					
				}
			});
		}
		
	}
}

function onSheetSelectionChange(Sh, Target) {
    var msg = "工作表" + Sh + "选中的区域是：" + Target.Address();
    //alert(msg);
	//console.log(msg);
	//onbuttonclick("createTaskPane");
	//console.log(Sh,Target);
	//console.log(Target.Address());
	//console.log("Select Target:",Target,msg);
	
	//wps.ShowDialog(GetUrlPath() + "/ui/dialog.html", "这是一个对话框网页", 400 * window.devicePixelRatio, 400 * window.devicePixelRatio, false)
	
	// 获取文件名
	let doc = wps.EtApplication().ActiveWorkbook
	let textValue = "";
	if (!doc){
		return ;
	}
	//console.log(doc);
	textValue = doc.Name;
	//console.log(textValue,Target.Column);

	wps.PluginStorage.setItem("select_rowtarget", JSON.stringify({"Row":Target.Row,"Column":Target.Column}));

	if(textValue.indexOf('倒模加工表')>0 && Target.Count == 1){
		let curSheet = wps.EtApplication().ActiveSheet;
		if (curSheet){
			let customerName = curSheet.Cells.Item(Target.Row,1).Text;
			let remarkText = curSheet.Cells.Item(Target.Row,2).Text;
			let drumNo = curSheet.Cells.Item(Target.Row,3).Text;
			let productName = curSheet.Cells.Item(Target.Row,4).Text;
			let dateSTR = curSheet.Cells.Item(2,5).Text;
			let coolingTotalWeight = curSheet.Cells.Item(Target.Row,17).Value2;
			let stoneWeightSTR = curSheet.Cells.Item(Target.Row,5).Formula;
			let stoneWeight = curSheet.Cells.Item(Target.Row,5).Value2;
			let coolingBoxWeight = curSheet.Cells.Item(Target.Row,19).Value2;
			let castingLoss = curSheet.Cells.Item(Target.Row,20).Value2;

			let data = {"customerName":customerName,"drumNo":drumNo,"productName":productName,"dateSTR":dateSTR,"access_token":access_token()};

			data.stoneWeight = stoneWeight;
			data.totalWeight = coolingTotalWeight;
			data.boxWeight = coolingBoxWeight;
			data.lossWeight = castingLoss;
			data.loginOpenID = getConfig().UserLoginOpenID;//"wto_I0024X4ycU2RpSQ9byGa4Q";// 热敏打印机的登录账号
			data.deviceSerial = getConfig().DeviceCode;//"DE2E2CF124F294F3A960E01DB91B0468"; //打印机的设备码 128机器上的
			wps.PluginStorage.setItem("select_rowdata", JSON.stringify(data));
		}
	}
	
	if(Target.Count == 1){
		let curSheet = wps.EtApplication().ActiveSheet;
		if (curSheet){
			//console.log() 
			// 将1行的数据序列化 变成JSON
			console.log("curSheet:",curSheet,Target.Row);
			let data = {};
			data.workbookName = wps.EtApplication().ActiveWorkbook.Name;
			data.sheetName = curSheet.Name;
			// 最大支持32列 格式如下{1:"a",2:"b"}
			for(let i = 1;i < 32;i++){
				let dataX = curSheet.Cells.Item(Target.Row,i).Text;
				if(dataX != "" && dataX.trim() != ""){
					//Reflect.defineProperty(data, "a"+i.toString(), {value: dataX});
					data[i.toString()] = encodeURIComponent(dataX.trim());
				}
			}
			
			data.dateSTR = curSheet.Cells.Item(2,5).Text;
			console.log("map JSON: ",data);
			data.loginOpenID = getConfig().UserLoginOpenID;//"wto_I0024X4ycU2RpSQ9byGa4Q";// 热敏打印机的登录账号
			data.deviceSerial = getConfig().DeviceCode;//"DE2E2CF124F294F3A960E01DB91B0468"; //打印机的设备码 128机器上的
			data.access_token = getConfig().AccessToken;//
			data.selectCellFormula = encodeURIComponent(Target.Formula);
			data.selectCellValue = Target.Value2;
			data.mainLoginOpenID = getMainClientUserLoginOpenID();
			data.mainDeviceSerial = getMainClientDeviceCode();
			
			wps.PluginStorage.setItem("any_select_rownum", Target.Row);
			wps.PluginStorage.setItem("any_select_rowdata", JSON.stringify(data));
		}
	}

	// 判断是否为“货量连石重” 列 21列
	// “原石重” 第5列
	if(textValue.indexOf('倒模加工表')>0 && Target.Column == 21 && Target.Count == 1){
		console.log("OK:" + textValue);
		// 显示任务窗格
		
		let curSheet = wps.EtApplication().ActiveSheet;
		if (curSheet){
			let customerName = curSheet.Cells.Item(Target.Row,1).Text;
			let remarkText = curSheet.Cells.Item(Target.Row,2).Text;
			let drumNo = curSheet.Cells.Item(Target.Row,3).Text;
			let productName = curSheet.Cells.Item(Target.Row,4).Text;
			let dateSTR = curSheet.Cells.Item(2,5).Text;
			let coolingTotalWeight = curSheet.Cells.Item(Target.Row,17).Value2;
			let orgStoneWeightSTR = curSheet.Cells.Item(Target.Row,5).Formula;
			let nowStoneWeightSTR = curSheet.Cells.Item(Target.Row,7).Formula;
			let coolingBoxWeight = curSheet.Cells.Item(Target.Row,19).Value2;
			let castingLoss = curSheet.Cells.Item(Target.Row,20).Value2;

			//console.log("17: ",curSheet.Cells.Item(Target.Row,17))
			//curSheet.Cells.Item(Target.Row,Target.Column).Formula = "=10.2+2.5";
			let url = getMainURL() + "/kim/queryProductWeightFormula";//?customerName="+customerName+"&drumNo="+drumNo+"&productName="+productName+"&dateSTR="+dateSTR+"&access_token=14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759"
			let data = {"customerName":customerName,"drumNo":drumNo,"productName":productName,"dateSTR":dateSTR,"access_token":"14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759"};
		
			wps.PluginStorage.setItem("taskpane_rowdata", JSON.stringify(data));
			wps.PluginStorage.setItem("taskpane_rowtarget", JSON.stringify({"Row":Target.Row,"Column":Target.Column}));

			data.coolingBoxWeight = coolingBoxWeight;
			data.castingLoss = castingLoss;
			wps.PluginStorage.setItem("select_rowdata", JSON.stringify(data));

			ActionJS.AjaxPostSP(url,data,function(result){
				console.log(result);
				if(result.errorCode == 1000 && result.productWeightFormula){
					curSheet.Cells.Item(Target.Row,Target.Column).Formula = result.productWeightFormula;
				}
				if(result.errorCode == 1000 && result.recycleWeight){
					curSheet.Cells.Item(Target.Row,23).Formula = result.recycleWeight;
				}
				if(result.errorCode == 1000 && result.cutBrokenWeight){
					curSheet.Cells.Item(Target.Row,24).Formula = result.cutBrokenWeight;
				}
			});
			// 

			console.log("%s 当前选择：客户：%s, 盅号：%s, 成色：%s",dateSTR,customerName,drumNo,productName);
			showTaskPanA(dateSTR,customerName,drumNo,productName,coolingTotalWeight,orgStoneWeightSTR,nowStoneWeightSTR);
		}
	}else if (textValue.indexOf('倒模加工表')>0 && Target.Column == 21 && Target.Count > 1){
		// 选择多行 展示统计数据
		console.log("选择多行 Target:",Target.Cells,Target.Areas.Count);
		let curSheet = wps.EtApplication().ActiveSheet;
		let dateSTR = curSheet.Cells.Item(2,5).Text;
		let drumNoArray = [];
		for(let i = 0;i<Target.Cells.Count;i++){
			let row = 0;
			if(Target.Cells.Areas.Count > 1){
				row = Target.Cells.Areas.Item(i+1).Row;
			}else{
				row = Target.Cells.Item(i+1).Row;
			}
			 
			console.log("行号：",row);
			let customerName = curSheet.Cells.Item(row,1).Text;
			let remarkText = curSheet.Cells.Item(row,2).Text;
			let drumNo = curSheet.Cells.Item(row,3).Text;
			let productName = curSheet.Cells.Item(row,4).Text;
			

			let data = {"customerName":customerName,"drumNo":encodeURIComponent(drumNo),"productName":productName,"dateSTR":dateSTR,"access_token":"14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759"};
			
			console.log("Row %d",i+1,Target.Rows.Item(i+1).Text);
			if(drumNo != "" && drumNo.trim() != ""){
				drumNoArray.push(encodeURIComponent(drumNo));
			}
			
			//console.log("data: ",data);
			//shwoTaskPanB(dateSTR,drumNoArraySTR);
		}
		let drumNoArraySTR = drumNoArray.join(",");
		console.log("选择：",drumNoArraySTR);
		showTaskPanB(dateSTR,drumNoArraySTR);
	}else if(textValue.indexOf('倒模加工表')>0 && Target.Column == 5 && Target.Count == 1){
		// 弹出网页对话框
		//console.log("target: 55,",Target)
		let curSheet = wps.EtApplication().ActiveSheet;
		if (curSheet){
			let customerName = curSheet.Cells.Item(Target.Row,1).Text;
			let drumNo = curSheet.Cells.Item(Target.Row,3).Text;
			let productName = curSheet.Cells.Item(Target.Row,4).Text;
			let stoneWeight = curSheet.Cells.Item(Target.Row,5).Text;
			let orgStoneWeight_exp = curSheet.Cells.Item(Target.Row,5).Formula;
			let dateSTR = curSheet.Cells.Item(2,5).Text;
			if(customerName && customerName.split("、").length > 1){
				//console.log("原石重：",stoneWeight);
				//
				let data = {"customerName":customerName,"drumNo":encodeURIComponent(drumNo),"productName":productName,"dateSTR":dateSTR,"access_token":"14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759"};
				onAfterOrgStoneWeightCellClick(Target,data);
				let url = getMainURL() + "/kim/loadOrgStoneWeightWin" + "?customerName="+customerName+"&drumNo="+encodeURIComponent(drumNo)+"&productName="+productName+"&dateSTR="+dateSTR+"&access_token=14F2C7EA82478136242077B86975BA5260C7DA4FC7A0F72993E90C5D6BD256C7D26608AD41AE1A3A9405B08C6C2A4692379A8D1DF32C600A9ADE7B6D93195D05A6B0E73B5CA856A31562F73C67C6C759";
				wps.onbeforeunload = onbeforeunload_handler;
				wps.onunload = onunload_handler;
				wps.ShowDialog(url, "原石重", 600 * window.devicePixelRatio, 400 * window.devicePixelRatio, true)

				

				//页面关闭之前触发，在onunload事件之前触发，可以禁止onunload事件的触发
				function onbeforeunload_handler(){
				var warning="确认退出?"; 
			debugger 
			return warning;
				}

				//页面关闭之后触发，这个事件执行完毕以后，页面就会关闭

				function onunload_handler(){
				var warning="谢谢光临";
				debugger
				alert(warning);
				}
			}else{

				let stoneWeight_exp = orgStoneWeight_exp;
				if(orgStoneWeight_exp.indexOf("=") == 0){
					stoneWeight_exp = orgStoneWeight_exp.substring(1);
				}
				// 更新石重
				let url = getMainURL() + "/kim/updateOrgStoneWeight";
				let data = {"customerName":customerName,"drumNo":encodeURIComponent(drumNo),"orgStoneWeight_exp":encodeURIComponent(stoneWeight_exp),"dateSTR":dateSTR};
				data.access_token = access_token();
				console.log(data);
				ActionJS.AjaxPostSP(url,data,function(result){
					console.log("原石重更新成功");
				});
			}
		}
	}else{
		let bFlag = wps.PluginStorage.getItem("EnableLockTaskFlag")
		if(!bFlag){
			hideTaskPanA();
		}
	}
	
}

function onAfterCalculate(Sh, Target){
	// 当前选中行的数据
	// wps.PluginStorage.setItem("any_select_rowdata", JSON.stringify(data));
	let any_row_string = wps.PluginStorage.getItem("any_select_rowdata");
	let any_row_data = JSON.parse(any_row_string);
	let any_select_rownum = wps.PluginStorage.getItem("any_select_rownum");
	// 列18：金结存
	// 列19：现金结存
	// 判断文件是否符合 2023年9月.xlsx 这种标准
	let dataSTR = wps.EtApplication().ActiveSheet.Cells.Item(1,1).Text;
	console.log("onAfterCalculate:",dataSTR,any_select_rownum,Sh);
	if(dataSTR != undefined && dataSTR.indexOf("出货核对单") > 0){
		let url = getMainURL() + "/kim/checkBalanceFromWpsJS";
		// find 单号
		let billNumber = "";
		let curSheet = wps.EtApplication().ActiveSheet;
		billNumber = curSheet.Cells.Item(any_select_rownum,3).Text;
		var find_rownum = any_select_rownum;
		var find_rowarray = [];
		find_rowarray.push(find_rownum);
		for(;;){
			if(billNumber == "" || billNumber.trim() == ""){
				find_rownum = find_rownum - 1;
				find_rowarray.push(find_rownum);
			}
			if(find_rownum <= 1){
				break;
			}
			if(billNumber != undefined && billNumber.length > 0){
				break;
			}
			billNumber = curSheet.Cells.Item(find_rownum,3).Text;
		}
		let data = {"goldBalance":any_row_data["18"],"cashBalance":any_row_data["19"],"customerName":any_row_data.sheetName,"billNumber":billNumber};
		data.access_token = access_token();
		// 更新计算之后的结果值
		curSheet = wps.EtApplication().ActiveSheet;
		//console.log("aaa:",curSheet.Cells.Item(any_select_rownum,18))
		data.goldBalance = curSheet.Cells.Item(any_select_rownum,18).Value2;
		data.cashBalance = curSheet.Cells.Item(any_select_rownum,19).Value2;

		ActionJS.AjaxPostSP(url,data,function(result){
			let curSheet = wps.EtApplication().ActiveSheet;
			//console.log("banlance:",result)
			if(result && result.errorCode == 1000){
				find_rowarray.forEach((i_rownum,index) => {
					let cell = curSheet.Cells.Item(i_rownum,18);
					cell.Font.Size = 12;
					cell.Font.Color = 255*180;
					cell = curSheet.Cells.Item(i_rownum,19);
					cell.Font.Size = 12;
					cell.Font.Color = 255*180;
	
					cell = curSheet.Cells.Item(i_rownum,3);
					cell.Font.Color = 0;
					cell.Font.Size = 12;
				});
				

			}else if(result.errorCode == 1004){
				// 金结存、现金结存不匹配
				let cell = curSheet.Cells.Item(any_select_rownum,18);
				cell.Font.Color = 255;
				cell.Font.Size = 16;

				cell = curSheet.Cells.Item(any_select_rownum,19);
				cell.Font.Color = 255;
				cell.Font.Size = 16;
			}else if(result.errorCode == 1005){
				// 金结存不匹配
				let cell = curSheet.Cells.Item(any_select_rownum,18);
				cell.Font.Color = 255;
				cell.Font.Size = 16;
			}else if(result.errorCode == 1006){
				// 现金结存不匹配
				let cell = curSheet.Cells.Item(any_select_rownum,19);
				cell.Font.Color = 255;
				cell.Font.Size = 16;
			}else if(result.errorCode == 1007){

				let cell = curSheet.Cells.Item(find_rownum,3);
				cell.Font.Color = 255;
				cell.Font.Size = 16;
				// 没有此单号
				alert("嘿! "+result.errorMsg);
				
			}else{
				console.log("未知异常错误");
			}
		});
	}
	
}

// 单元格选择区域改变事件
Application.ApiEvent.AddApiEventListener("SheetSelectionChange", onSheetSelectionChange);
Application.ApiEvent.AddApiEventListener("AfterTaskPaneHidden", onAfterTaskPaneHidden);
Application.ApiEvent.AddApiEventListener("AfterTaskPaneShow", onAfterTaskPaneShow);
Application.ApiEvent.AddApiEventListener("WorkbookAfterSave", onFileAfterSave); 
Application.ApiEvent.AddApiEventListener("AfterCalculate", onAfterCalculate); 

function openOfficeFileFromSystemDemo(param){
    let jsonObj = (typeof(param)=='string' ? JSON.parse(param) : param)
    alert("从业务系统传过来的参数为：" + JSON.stringify(jsonObj))
    return {wps加载项项返回: jsonObj.filepath + ", 这个地址给的不正确"}
}

function InvokeFromSystemDemo(param){
    let jsonObj = (typeof(param)=='string' ? JSON.parse(param) : param)
    let handleInfo = jsonObj.Index
    switch (handleInfo){
        case "getDocumentName":{
            let docName = ""
            if (wps.EtApplication().ActiveWorkbook){
                docName = wps.EtApplication().ActiveWorkbook.Name
            }

            return {当前打开的文件名为:docName}
        }

        case "newDocument":{
            let newDocName=""
            let doc = wps.EtApplication().Workbooks.Add()
            newDocName = doc.Name
            
            return {操作结果:"新建文档成功，文档名为：" + newDocName}
        }

        case "OpenFile":{
            let filePath = jsonObj.filepath
            wps.EtApplication().Workbooks.OpenFromUrl(filePath)
            return {操作结果:"打开文件成功"}
        }
    }

    return {其它xxx:""}
}
